#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <list>
#include <vector>

using namespace std;

#define mod 11

int hashFunction(int key) 
{
	return key % mod;
}

void insert(int key, vector<list<int>>& hashTable)
{
	int hashValue = hashFunction(key);
	hashTable[hashValue].push_front(key);
}

void search(int key, vector<list<int>>& hashTable)
{
    int hashValue = hashFunction(key);
    int count = 0;
    for (auto it = hashTable[hashValue].begin(); it != hashTable[hashValue].end(); it++) 
    {
        count++;
        if (*it == key) 
        {
            cout << hashValue << " " << count << endl;
            return;
        }
    }
    cout << "error" << endl;
    insert(key,hashTable);
}

void test5()
{
    int n, k, data;
    while (scanf("%d", &n) != EOF)
	{
        vector<list<int>> hashTable(mod);

        for (int i = 0; i < n; i++) 
        {
            cin >> data;
            insert(data, hashTable);
        }
        cin >> k;
        for (int i = 0; i < k; i++) 
        {
            cin >> data;
            search(data, hashTable);
        }
	}
}

int main()
{
	test5();
	return 0;
}
